package com.example.jetpackpaging.net

import android.util.Log
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitClient {

    private val instance: Retrofit by lazy {

        val intercepter = HttpLoggingInterceptor(HttpLoggingInterceptor.Logger{
            Log.i("info","请求日志:"+it)
        })
        intercepter.level = HttpLoggingInterceptor.Level.HEADERS

        Retrofit.Builder()
            .baseUrl("https://api.github.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .client(OkHttpClient.Builder().addInterceptor(intercepter).build())
            .build()

    }

    fun <T> createApi(clazz: Class<T>): T{
        return instance.create(clazz) as T
    }

}